package io.netty.example.test.my;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.handler.timeout.ReadTimeoutException;

import java.net.ConnectException;
import java.net.SocketAddress;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author John zhang
 * @version 0.1
 */
public class DelegateClientChannelOutBoundHandler extends ChannelOutboundHandlerAdapter {

	private static final Logger logger = Logger.getLogger ( DelegateClientChannelOutBoundHandler.class.getSimpleName () );

	@Override
	public void bind( ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise ) throws Exception {
		super.bind ( ctx, localAddress, promise );
		logger.info ( "bind" );
	}

	@Override
	public void connect( ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise ) throws Exception {
		super.connect ( ctx, remoteAddress, localAddress, promise );
		logger.info ( "connect remoteAddress = " + remoteAddress + " localAddress = " + localAddress );
	}

	@Override
	public void disconnect( ChannelHandlerContext ctx, ChannelPromise promise ) throws Exception {
		super.disconnect ( ctx, promise );
		logger.info ( "disconnect" );
	}

	@Override
	public void close( ChannelHandlerContext ctx, ChannelPromise promise ) throws Exception {
		super.close ( ctx, promise );
		logger.info ( "close" );
	}

	@Override
	public void deregister( ChannelHandlerContext ctx, ChannelPromise promise ) throws Exception {
		super.deregister ( ctx, promise );
		logger.info ( "deregister" );
	}

	@Override
	public void read( ChannelHandlerContext ctx ) throws Exception {
		super.read ( ctx );
		logger.info ( "connect" );
	}

	@Override
	public void write( ChannelHandlerContext ctx, Object msg, ChannelPromise promise ) throws Exception {
		super.write ( ctx, msg, promise );
		logger.info ( "write" );
	}

	@Override
	public void flush( ChannelHandlerContext ctx ) throws Exception {
		super.flush ( ctx );
		logger.info ( "flush" );
	}

}
